home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / x25 / nrs.shar.Z / nrs.shar / nrs.SH < prev    next >
Encoding:
Text File  |  1990-04-27  |  14.5 KB  |  534 lines

  1. case $CONFIG in
  2.     '') . config.sh ;;
  3. esac
  4. outputfile=nrs.h
  5. rm -f $outputfile.$$
  6. echo "Creating $outputfile (with variable substitutions)"
  7. if cat >$outputfile.$$ <<!GROK!THIS!
  8. #ifndef lint
  9. static char NrsId[] = "@(#)$Header: nrs.SH,v 3.6 88/09/08 17:41:19 pb Exp $";
  10. #endif lint
  11.  
  12. /* Copyright 1986, Piete Brooks, Julian Onions & Adrian Pell
  13.  *      pb@cl.cam.ac.uk, jpo@hcig.nott.ac.uk, Adrian.R.Pell@reading.ac.uk
  14.  *
  15.  * This program may be copied as long as you don't remove this notice,
  16.  * try to make any money off of it, or pretend that you wrote it.
  17.  */
  18.  
  19. #include    <stdio.h>
  20. #include    <ctype.h>
  21.  
  22. /* Define one of these if needed */
  23. #$vms21    VMS21        /* VAX VMS C 2.1 (used in nrs.h & misc)    */
  24. #$prime    PRIME        /* PR1ME                */
  25. #$novoid    VOID        /* V7 doesn't understand (void)        */
  26.  
  27. #$memset    bzero(a,b)    memset((a), 0, (b))
  28. #$strchr    index    strchr
  29. #$gethostname    USE_GETHOSTNAME        /* Use BSD gethostname() */
  30. #$uname    USE_UNAME        /* Use USG uname()    */
  31.  
  32. /* Options .... */
  33. #$fyork    F_YORK        /* york output format enabled */
  34. #$fx25hosts    F_X25HOSTS    /* /etc/x25hosts format    */
  35. #$fmmdf    F_MMDF        /* mmdf format enabled    */
  36. #$ftext    F_TEXT        /* text format enabled    */
  37. #$fsmail    F_SMAIL        /* reading sendmail format */
  38. #$fvms4    F_VMS4        /* vms format 4 enabled    */
  39. #$fvms5    F_VMS5        /* vms format 5 enabled    */
  40. #$fsendmail    F_SENDMAIL    /* UK sendmail format    */
  41. #$fyork21    F_YORK21    /* york output format enabled */
  42. #$fdbm1    F_DBM1        /* ucl dbm format */
  43. #$fprime    F_PRIME        /* PRIME text format */
  44. #$fedtext    F_EDTEXT    /* Edinburgh text format */
  45. #$fvme    F_VME        /* VME mail format */
  46. #$fpp    F_PP        /* PP format */
  47.  
  48. #$mmdfboth    MMDF_CHAN_BOTH_FORMS    /* Long AND short in mmdf.chan tables ?    */
  49.  
  50. /* Dependant info ... */
  51. #ifdef PRIME
  52. # include    <time.h>
  53. # define    off_t    Header
  54. # define    time_t    struct tm
  55. # define    static_f
  56. # define    universaluse(x)    (char *) (x)
  57. # define    universaldec(x)    char * x;
  58. # undef        UNIX
  59. #else    PRIME
  60. # include    <sys/types.h>
  61. #endif PRIME
  62.  
  63. #ifdef    VMS21
  64. # include    <stat.h>    /* For time_t        */
  65. # define exit_rc(x)    (!x)    /* lowest bit SET -> OK */
  66. # undef  UNIX            /* This ain't UNIX !    */
  67. #else VMS21
  68. # define noshare
  69. #endif    VMS21
  70.  
  71. #ifndef    VOID
  72. # define VOID (void)
  73. #endif    VOID
  74.  
  75. #define    gettab(n)    (fnumb2trip[n].f_tp)
  76. #define    findtriple(n)    ((gettab(n)) ? &((gettab(n))->hdr) : NULL)
  77. #ifndef static_f
  78. # define    static_f    static
  79. #endif static_f
  80. #ifndef    universaldec
  81. # define    universaldec(x)
  82. # define    universaluse(x)    x
  83. #endif    universaldec
  84. #ifndef    exit_rc
  85. # define exit_rc(x)    x
  86. #endif    exit_rc
  87.  
  88. #define    warn0(rc, f)        warn_3(rc, f, universaluse(0), universaluse(0), universaluse(0))
  89. #define    warn1(rc, f, a1)    warn_3(rc, f, universaluse(a1), universaluse(0), universaluse(0))
  90. #define    warn2(rc, f, a1, a2)    warn_3(rc, f, universaluse(a1), universaluse(a2), universaluse(0))
  91. #define    warn3(rc, f, a1, a2,a3)    warn_3(rc, f, universaluse(a1), universaluse(a2), universaluse(a3))
  92.  
  93. #define    fatal0(f)        fatal_2(f, universaluse(0), universaluse(0))
  94. #define    fatal1(f, a1)        fatal_2(f, universaluse(a1), universaluse(0))
  95. #define    fatal2(f, a1, a2)    fatal_2(f, universaluse(a1), universaluse(a2))
  96.  
  97. #define    vprintf0(n, f) \
  98.     vprintf_3(n, f, universaluse(0), universaluse(0), universaluse(0))
  99. #define    vprintf1(n, f, a1) \
  100.     vprintf_3(n, f, universaluse(a1), universaluse(0), universaluse(0))
  101. #define    vprintf2(n, f, a1, a2) \
  102.     vprintf_3(n, f, universaluse(a1), universaluse(a2), universaluse(0))
  103. #define    vprintf3(n, f, a1, a2, a3) \
  104.     vprintf_3(n, f, universaluse(a1), universaluse(a2), universaluse(a3))
  105.  
  106. # define    TRUE        1
  107. # define    FALSE        0
  108. # define    UNSET        -1    /* not yet set to anything    */
  109. # define    KEEPOPEN    01    /* keep file open        */
  110. # define    GETFNUMBER    02    /* file has a file number    */
  111. # define    SEEKFNUMBER    04    /* file number must be sought */
  112. # define    MAXQUADS    80    /* max quads we can cope with    */
  113. # define    MAX_FNUMB    50    /* max number of atomic files    */
  114. # define    MOD2        "MODULE2"    /* default module2 name */
  115. # define    MOD3        "MODULE3"    /* default module3 name */
  116. # define    MOD4        "MODULE4"    /* default module4 name */
  117. # define    DERFIL_D1    "DERFIL2"    /* default number 1    */
  118. # define    DERFIL_D2    "DERFIL1"    /* default number 2    */
  119. # define    MAXNAMELEN    128    /* generally large string    */
  120. # define    MAXAR        10    /* max application relays    */
  121. # define    MAXDESC        10    /* max description lines    */
  122. # define    TAGSIZE        6    /* size of tag in atomic files    */
  123. # define    MAXTABLES    40    /* maximum atomic files in table*/
  124. # define    MAXDOMAINS    20    /* maximium domains for mmdf    */
  125. # define    MAXLOCDOMAINS    20    /* max loc domains for york    */
  126. # define    MAGIC        '$'    /* magic char in comments    */
  127. # define    DCONTEXTS    10    /* Max number of domain contexts*/
  128.  
  129. /* atomic files fields */
  130. # define    DT        1    /* dte stuff        */
  131. # define    YB        2    /* Yellow book        */
  132. # define    AR        3    /* application relay    */
  133. # define    DI        4    /* description        */
  134.  
  135. /* long and the short of it */
  136. # define    LONG        1    /* long name    */
  137. # define    SHORT        2    /* short name    */
  138. # define    FORWARD        3    /* map forwards    */
  139. # define    REVERSE        4    /* map reverse    */
  140. # define    MIXED        5    /* mixed case    */
  141. # define    LOWER        6    /* lower case    */
  142. # define    IGNORERELAY    7    /* ignore application relay strings --
  143.                      * e.g. in VMS still generate entry */
  144.  
  145. /* Contexts that we're interested in */
  146. # define    X29        1    /* x29 context */
  147. # define    TS29        2
  148. # define    NIFTP        3    /* ftp blue book context */
  149. # define    MAIL_NIFTP    4    /* grey book mail context */
  150. # define    MAIL_X29    5
  151. # define    MAIL_TELEX    6
  152. # define    JTMP        7
  153. # define    JTMP_FILES    8
  154. # define    JTMP_REG    9
  155. # define    YBTS_NODE    10
  156. # define    YBTS        11
  157. # define    DESC        12
  158. # define    MAXCONTEXTS    (DESC+1)
  159.  
  160. /* the networks */
  161. # define    PSS        1
  162. # define    JANET        2
  163. # define    TELEX        3
  164. # define    MAXSUBNETS    (TELEX+1)
  165.  
  166. # define    max(X,Y)    ((X) < (Y)? (Y) : (X))
  167. # define    min(X,Y)    ((X) > (Y)? (Y) : (X))
  168.  
  169. typedef    short /*int*/ small;    /* V7: remove int ?? */
  170.  
  171. /* structure of the Module2 file */
  172. typedef struct mod2 {
  173.     int    index_disp;    /* index into module4    */
  174.     int    ls_disp;    /* index into module2    */
  175.     small    ls;        /* long/short flag    */
  176.     small    length;        /* length of string    */
  177.     char    name[MAXNAMELEN];    /* the string    */
  178. } Mod2;
  179.  
  180. /* structure of the module3 file */
  181. typedef struct mod3 {
  182.     small    m3_context;
  183.     small    m3_network;
  184.     small    m3_direction;
  185.     int    l_disp;
  186.     char    m3_dte[MAXNAMELEN];
  187.     char    m3_ybts[MAXNAMELEN];
  188. /*    char    m3_desc[MAXNAMELEN];    */
  189.     small    m3_length;
  190.     char    m3_string[MAXNAMELEN];
  191. } Mod3;
  192.  
  193. /* The quad structure */
  194. typedef struct Quad {
  195.     small    fnumb;    /* the file number to find it in    */
  196.     int    ngtwys;    /* the no. of gateways (what the hell is this?)    */
  197.     int    disp;    /* the displacement in the file        */
  198.     small    nlines;    /* the number of lines in the file    */
  199. } Quad;
  200.  
  201. /* structure of the module4 file */
  202. typedef struct mod4 {
  203.     small    nquads;    /* the number of quads    */
  204.     Quad    quads[MAXQUADS+1];    /* the quads */
  205. } Mod4;
  206.  
  207. /* the file header - one for each file */
  208. typedef struct Header {
  209.     int    H_nlines;    /* no. of lines in file    */
  210.     int    fnumber;    /* the file number    */
  211.     long    *offset;    /* lines to seek values    */
  212. } Header;
  213.  
  214. typedef    struct    Table {
  215.     char    *T_name;    /* the file name        */
  216.     small    T_context;    /* the context            */
  217.     small    T_network;    /* the network            */
  218.     small    T_direction;    /* the direction        */
  219.     Header    hdr;        /* The header for the file    */
  220. } Table;
  221.  
  222. #define    DIR_FORWARDS    1
  223. #define    DIR_REVERSE    2
  224. #define    MAXDIRECTIONS    (DIR_REVERSE+1)
  225.  
  226.  
  227. /* structure for the atomic file    */
  228. typedef    struct    atomic {
  229.     char    *dte;        /* The dte string    */
  230.     char    *ybts;        /* the yb string    */
  231.     char    *desc[MAXDESC];    /* the description    */
  232.     small    n_descs;    /* number of desc's    */
  233.     small    n_relays;    /* number of ar's    */
  234.     char    *ar[MAXAR];    /* the application relays    */
  235.     small    context;    /* what context this is in    */
  236.     small    network;    /* which subnet this is on    */
  237.     small    direction;    /* which direction this is    */
  238. } Atomic;
  239.  
  240. typedef struct    domain {    /* domain information (DERFIL2 only) */
  241.     char    name[MAXNAMELEN];    /* name of domain */
  242.     char    gateway[MAXNAMELEN];    /* gateway name or address */
  243.     int    n_contexts;        /* number of contexts */
  244.     int    contexts[DCONTEXTS];    /* contexts */
  245. } Domain;
  246.  
  247. typedef    struct    lookup {    /* struct used by lookup() routines */
  248.     char    *str;
  249.     int    value;
  250. } Lookup;
  251.  
  252. typedef struct version {
  253.     int    hours;
  254.     int    minutes;
  255.     int    day;
  256.     int    month;
  257.     int    year;
  258.     int    format;
  259. } Version;
  260.  
  261. struct f2t{
  262.     small    f_cont;
  263.     small    f_subn;
  264.     small    f_dirn;
  265.     struct    Table *f_tp;
  266. };
  267.  
  268. Header    Module2;    /* info on the module 2 file */
  269. Header    Module3;    /* info on the module 4 file */
  270. Header    Module4;    /* info on the module 4 file */
  271. Header    Domains;    /* info on the domains file */
  272. Version    thisversion;    /* the current database version */
  273.  
  274. extern    Table    tablist[];    /* the table of files */
  275. extern    Lookup    contexts[];    /* list of contexts */
  276. extern    Lookup    netnames[];    /* list of networks */    
  277. extern    Lookup    lc_netnames[];    /* list of networks in lower case */    
  278. extern    Lookup    netabbrevs[];    /* network abbreviations */
  279. extern    Lookup    directions[];    /* list of directions */
  280. #ifdef    F_YORK
  281. extern    Lookup    def_ybstring[];    /* list of default  yb service names    */
  282. extern    Lookup    imp_services[];    /* list of implicit yb service names    */
  283. extern    Lookup    exp_services[];    /* list of explicit yb service names    */
  284. #endif    F_YORK
  285. #ifdef    F_YORK21
  286. #ifndef    F_YORK
  287. extern    Lookup    def_ybstring[];    /* list of default  yb service names    */
  288. #endif    F_YORK
  289. extern    Lookup    exp_21services[]; /* list of explicit yb service names    */
  290. #endif    F_YORK21
  291. #ifdef    F_VMS4
  292. extern    Lookup    vms4_services[]; /* list of vms context name        */
  293. #endif    F_VMS4
  294. #ifdef    F_VMS5
  295. extern    Lookup    vms5_services[]; /* list of vms context name        */
  296. #endif    F_VMS5
  297. #ifdef    F_DBM1
  298. #define    DBSEP        '\034'
  299.  
  300. #define    R_MAIN        '#'
  301. #define    R_ALIAS        '>'
  302. #define    R_REV        '$'
  303. #define    R_DOMAIN    '@'
  304.  
  305. #define    DEF_MAXFTP    50
  306. #define    DEF_LOCAL    0
  307. #define    DEF_OLD        0
  308. #define    DEF_DISABLED    0
  309. #endif    F_DBM1
  310. #ifdef    F_PRIME
  311. int    primeformat();
  312. int    primedomain();
  313. #endif    F_PRIME
  314.  
  315. Mod2    *getm2rec();
  316. Mod3    *getm3rec();
  317. Mod4    *getm4rec();
  318. Atomic    *getatrec();
  319. #ifndef    gettab
  320. Table    *gettab();
  321. #endif    gettab
  322. char    *vlookup();
  323. char    *lowerfy();
  324. FILE    *getfp();
  325. int    noformat();
  326.  
  327. # ifdef    F_YORK
  328. int    yorkformat();
  329. #define    COLON    ((char) (':' | 0x80))
  330. # endif    F_YORK
  331.  
  332. # ifdef    F_X25HOSTS
  333. int    x25hostsformat();
  334. # endif    F_X25HOSTS
  335.  
  336. # ifdef    F_MMDF
  337. int    mmdfformat();
  338. int    mmdfdomain();
  339. #define FLIP
  340. #define MULT_OUTPUT_FILES
  341. # endif    F_MMDF
  342.  
  343. # ifdef    F_TEXT
  344. int    textformat();
  345. # endif    F_TEXT
  346.  
  347. # ifdef    F_VMS4
  348. int    vms4m4rec();
  349. # endif    F_VMS4
  350.  
  351. # ifdef    F_VMS5
  352. int    vms5m4rec();
  353. # endif    F_VMS5
  354.  
  355. # ifdef    F_EDTEXT
  356. int    edtextm4rec();
  357. int    edtextformat();
  358. int    edtextdomain();
  359.  
  360. #define    FL_CNTX    4    /* Width of the first field (context)        */
  361. #define    FL_NET    1    /* Width of network field            */
  362. #define    FL_DOM    10    /* Width of domain name (in domain section)    */
  363. #define    FL_PREF1    18    /* Width of "shortform" prefix        */
  364. #define    FL_PREF2    22    /* Width of "longform" prefix        */
  365.  
  366. #define    O_ED_MASK    0x0007
  367. #define    O_ED_LONG    0x0004
  368. #define    O_ED_SHORT    0x0002
  369. #define    O_ED_SIMPLE    0x0001
  370. #define    O_ED_DEFAULT    O_ED_SHORT
  371. # endif    F_EDTEXT
  372.  
  373. # ifdef    F_SMAIL
  374. int    smailformat();
  375. # endif    F_SMAIL
  376.  
  377. # ifdef    F_SENDMAIL
  378. int    sendmailformat();
  379. int    sendmaildomain();
  380. #define FLIP
  381. #define MULT_OUTPUT_FILES
  382. # endif    F_SENDMAIL
  383.  
  384. # ifdef    F_YORK21
  385. int    york21m4rec();
  386. #  ifndef    COLON
  387. #define    COLON    ((char) (':' | 0x80))
  388. #  endif    COLON
  389. # endif    F_YORK21
  390.  
  391. #ifdef    F_DBM1
  392. int    dbm1m4rec();
  393. int    dbm1format();
  394. int    dbm1domain();
  395. #endif    F_DBM1
  396.  
  397. # ifdef    F_VME
  398. int    vmem4rec();
  399. int    vmedomain();
  400.  
  401. #define    VME_HFTFLEN    2
  402. #define    VME_HNRSALEN    2
  403. #define    VME_HNRSBLEN    2
  404. #define    VME_SERCNLEN    6
  405. #define    VME_PROPCNLEN    4
  406. #define    VME_MAILSRLEN    1
  407. #define    VME_LFTFLEN    32
  408. #define    VME_NRSALEN    18
  409. #define    VME_NRSBLEN    127
  410. #define    VME_ROUCNLEN    6
  411. #define    VME_SERCN_SEP    999999
  412. #define    VME_SERCN_RELAY    888888
  413. #define    VME_PROPCN_ROUTE    32
  414. #define    VME_STRIP    "UK.AC."
  415. # endif    F_VME
  416.  
  417. # ifdef    F_PP
  418. int    ppm4rec();
  419. int    ppdomain();
  420. #define FLIP
  421. #define MULT_OUTPUT_FILES
  422. # endif    F_PP
  423.  
  424. # ifdef    MULT_OUTPUT_FILES
  425. # define    LOCAL    01
  426. # define    USED    02
  427.  
  428. typedef    struct file_list {
  429.     char    *dname;        /* domain name - short form        */
  430.     char    *ldname;    /* domain name - long form        */
  431.     char    *fname;        /* the file associated with above    */
  432.     small    net;        /* the associated network if any    */
  433.     small    flags;        /* various flags - see above        */
  434. } File_list;
  435.  
  436. extern    File_list fil_list[];    /* list of mmdf domains & channels    */
  437. extern    char    *relay_host;    /* relay host to janet            */
  438. #endif    MULT_OUTPUT_FILES
  439.  
  440. extern    char    *calloc();
  441. extern    char    *strdup();
  442. extern    char    *strcpy();
  443. extern    char    *strncpy();
  444. extern    char    *strcat();
  445. extern    char    *malloc();
  446. extern    char    *index();
  447. extern    char    *getfpath();
  448. extern    int    (*outputm4rec)();  /* output a complete m4 record */
  449. extern    int    (*outputformat)();
  450. extern    int    (*outputdomain)(); /* output a domain record */
  451.  
  452. extern    char    *invo_name;    /* the prog name (argv[0]) */
  453. extern    int    trip2fnumb[MAXCONTEXTS][MAXSUBNETS][MAXDIRECTIONS];
  454. extern    int    cont_want[MAXCONTEXTS];
  455. extern    struct f2t fnumb2trip[MAX_FNUMB];
  456.                 /* Map triple to file number    */
  457. extern    int    max_fnumb;    /* the max file number we've got*/
  458. extern    int    fnumb;        /* the max file number */
  459. extern    int    ignore_relay;    /* ignore application relay strings --
  460.                  * e.g. in VMS still generate entry */
  461. extern    int    verbose;    /* verbosity level        */
  462. extern    int    warns;        /* Count of warns so far    */
  463. extern    int    max_warns;    /* max number of warns        */
  464. extern    int    forwrev;    /* forward/reverse lookup    */
  465. extern    int    longshort;    /* is long or short form used ?    */
  466. extern    int    mixlow;        /* mixed/lower case        */
  467. extern    int    usederfil;    /* use derived file             */
  468. extern    int    options;    /* output specific options    */
  469. extern    char    nullstring[];    /* The null string (no value)    */
  470. extern    char    *M2file;    /* the Module2 file name    */
  471. extern    char    *M3file;    /* the module3 file name    */
  472. extern    char    *M4file;    /* the module4 file name    */
  473. extern    char    *Derfile;    /* the derived file name        */
  474. extern    char    *DOMfile;    /* the domain file name        */
  475. extern    char    *janetgateway;    /* gateway to janet        */
  476. extern    char    *pssgateway;    /* gateway to pss        */
  477. extern    char    *directory;    /* the unix directory for files */
  478. extern    char    *stripoff;    /* strip off this prefix in output */
  479. extern    char    *hostname;    /* the name of this host    */
  480. extern    char    *commentfile;    /* the file with comments in     */
  481.  
  482. extern int atoi();
  483. extern int free();
  484. extern int strcmp();
  485. extern int fclose();
  486. extern int setlinebuf();
  487. extern int gethostname();
  488. extern int fseek();
  489. extern int exit();
  490. #ifndef SYSTEM_FIVE
  491. extern char     *sprintf();
  492. #else
  493. extern int      sprintf();
  494. #endif
  495. extern int fprintf();
  496. extern int _flsbuf();
  497. extern int _filbuf();
  498. extern int ungetc();
  499. extern int strlen();
  500. extern int time();
  501. extern int fputs();
  502. extern int printf();
  503. extern int fflush();
  504. extern int strncmp();
  505. extern int bzero();
  506.  
  507. int slookup();
  508. int getint();
  509. void skipnl();
  510. void freeoff();
  511. void vprintf_3();
  512. void getstr();
  513. void consistant();
  514. void addcomments();
  515. void config();
  516.  
  517. int lexequ();
  518. void fatal_2();
  519. void warn_3();
  520. !GROK!THIS!
  521. then if cmp $outputfile $outputfile.$$ > /dev/null 2>& 1
  522.     then
  523.         rm -f $outputfile.$$
  524.         echo "    " $outputfile not affected
  525.     elif mv $outputfile.$$ $outputfile
  526.     then
  527.         echo "    " $outputfile updated
  528.     else
  529.         echo "+++    " $outputfile left in $outputfile.$$
  530.     fi
  531. else
  532.     echo "    " Failed to create $outputfile.$$
  533. fi
  534.